package com.syezon.wifikey.news;

import android.animation.ValueAnimator;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.SizeUtils;
import com.syezon.wifikey.R;
import com.syezon.wifikey.base.BaseFragment;

import butterknife.BindView;

public class SpeedUpResultFragment extends BaseFragment {

    private static final String ARG_ADD = "arg_add";

    @BindView(R.id.fl_content)
    FrameLayout mFlContent;
    @BindView(R.id.tv_speed_up_value)
    TextView mTvAddValue;
    private Handler mHandler = new Handler();

    public SpeedUpResultFragment() {
    }


    public static SpeedUpResultFragment newInstance(int add) {
        SpeedUpResultFragment fragment = new SpeedUpResultFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_ADD, add);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.app_news_layout_speedup_result;
    }

    @Override
    protected void initViewsAndEvents() {
        Bundle arguments = getArguments();
        if (arguments != null && arguments.getInt(ARG_ADD, 0) > 0) {
            int add = arguments.getInt(ARG_ADD, 0);
            if (add >= 100) {
                mTvAddValue.setText("网速评分97分");
                mTvAddValue.setVisibility(View.GONE);
            } else {
                mTvAddValue.setText("网速评分+" + add + "分");
                mTvAddValue.setVisibility(View.VISIBLE);
            }
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    ValueAnimator valueAnimator = ValueAnimator.ofInt(SizeUtils.dp2px(200), SizeUtils.dp2px(80)).setDuration(500);
                    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            int height = (int) animation.getAnimatedValue();
                            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) mFlContent.getLayoutParams();
                            marginLayoutParams.height = height;
                            mFlContent.setLayoutParams(marginLayoutParams);
                        }
                    });
                    valueAnimator.start();
                }
            }, 1000);
        }
    }

}
